
<template>
  <a-row :gutter="24">
    <a-alert type="success" style="margin-bottom: 10px">默认数据库表名前缀为:{{ from.table_prefix }}，
      如果想修改默认前缀，请修改.env 默认配置
    </a-alert>
    <a-col :span="12">
      <BhForm ref="formRef" v-model:model-value="from" :options="options" :columns="formColumns"/>
    </a-col>
    <a-col :span="12">
    </a-col>
  </a-row>
</template>
<script setup lang="ts">
import {BhForm, type Columns, type Options} from '@/components/BhForm'
import {AnyObject} from "@/types/global";
import {computed} from "vue";

const props = withDefaults(
    defineProps<
        Partial<{
          modelValue: AnyObject;
        }>
    >(),
    {

    }
);
const emits = defineEmits(['update:modelValue']);
const from = computed({
  get() {
    return props.modelValue;
  },
  set(e) {
    emits('update:modelValue', e);
  },
});
const options: Options = {
  form: {size: 'large'},
  btns: {hide: true},
}
const formRef = ref<InstanceType<typeof BhForm>>()
const formColumns: Columns = reactive([
  {
    label: '表名称',
    field: 'table_name',
    type: 'input',
    disabled: true,
  },
  {
    label: '表备注',
    field: 'table_comment',
    type: 'input',
    disabled: true,
  },
  {
    label: '表前缀',
    field: 'table_prefix',
    type: 'input',
    disabled: true,
  },
  {
    label: '注释信息',
    field: 'note',
    type: 'input',
    props: {
      placeholder: '请输入注释信息',
    },
    rules: [{required: true, message: '请输入注释信息'}],
  },
  {
    label: '作者名称',
    field: 'author',
    type: 'input',
    props: {
      placeholder: '请输入作者名称',
    },
    rules: [{required: true, message: '请输入作者名称'}],
  },
  {
    label: '业务时间',
    field: 'time',
    type: 'date-picker',
    props: {
      placeholder: '请选择业务时间',
    },
    rules: [{required: true, message: '请选择业务时间'}],
  },
])
const onValidate =  async() => {
  return await formRef.value?.formRef?.validate();
}
defineExpose({onValidate})
</script>
<style scoped lang="less">

</style>